package com.csjy.migration.hnnd;

import com.csjy.migration.hnnd.business.SourceBusinessData;
import com.csjy.migration.hnnd.dict.NewProcessDefId;

import javax.script.ScriptException;
import java.math.BigDecimal;
import java.sql.*;
import java.time.Period;
import java.util.*;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import static com.csjy.migration.hnnd.Tool.covertToBigDecimal;

public class BusinessTool {
  public static Map<String,Map<String,String>> procDefAndTaskDefMigrationIdMap = new HashMap<>();
  public static List<Map> oldDictList = new ArrayList<>();
  public static List<Map> oldEmployeeList = new ArrayList<>();
  public static Map<String,String[]> taskDefNameAndKeyMap = new HashMap<>();
  public static List<Object> migratedUndoneWorkflowIdList = new ArrayList<>();
  public static DbUtil targetDbUtil;

  /**
   * 初始化
   * @param sourceDbUtil
   * @param targetDbUtil
   * @throws SQLException
   */
  public static void init(DbUtil sourceDbUtil, DbUtil targetDbUtil) throws SQLException {
    BusinessTool.targetDbUtil = targetDbUtil;
    // 查询migration_id_map
    findProdDefAndTaskDefMigrationIdMap(targetDbUtil);
    // 查询老系统数据字典
    oldDictList = sourceDbUtil.selectByParams("SELECT DICT_CODE,DATA_CODE,DATA_NAME FROM FT_DICT_DATA ", new ArrayList());
    // 老系统员工表
    oldEmployeeList = sourceDbUtil.selectByParams("SELECT EMPNAME,EMPCODE FROM jwframe.FT_EMPLOYEE  WHERE TOPORGID  = 9051 ", new ArrayList());
    // 已迁移正在运行中的流程id集合
    migratedUndoneWorkflowIdList = targetDbUtil.selectSingleColumn("\n" +
        "select distinct a.proc_inst_id_ from (\n" +
        "  select distinct aht.proc_inst_id_ from act_hi_taskinst aht\n" +
        "  where aht.proc_inst_id_ like '%JW%' and aht.id_ not like '%JW%'\n" +
        "  union\n" +
        "  select distinct art.proc_inst_id_ from act_ru_task art\n" +
        "  where art.proc_inst_id_ like '%JW%'\n" +
        ") a\n" +
        "\n", new ArrayList());

    // ====任务名称和key映射集合====

    // 项目文件归档
    taskDefNameAndKeyMap.put("项目文件归档@责任人提交资料清单",new String[]{"责任人提交资料清单","task1535420321532"});
    taskDefNameAndKeyMap.put("项目文件归档@档案管理员接收处理",new String[]{"档案管理员接收处理","task1535420355624"});

    // 项目受理流程
    taskDefNameAndKeyMap.put("项目受理@受理人提交资料",new String[]{"受理人提交资料","task1540522640244"});
    taskDefNameAndKeyMap.put("项目受理@A经理出调查协议",new String[]{"A经理出调查协议","task1540522793884"});
    taskDefNameAndKeyMap.put("项目受理@办事处负责人审批",new String[]{"办事处负责人审批","task1540522661934"});
    taskDefNameAndKeyMap.put("项目受理@分公司负责人审批",new String[]{"分公司负责人审批","task1540522687036"});
    taskDefNameAndKeyMap.put("项目受理@公司融资部审批",new String[]{"公司融资部审批","task1540522730148"});
    taskDefNameAndKeyMap.put("项目受理@林业项目部审批",new String[]{"公司融资部审批","task1540522730148"});
    taskDefNameAndKeyMap.put("项目受理@业务副总经理审批",new String[]{"业务副总经理审批","task1540522755139"});
    taskDefNameAndKeyMap.put("项目受理@审计内勤指派事务所",new String[]{"审计内勤指派事务所","task1540522825190"});

    // 提交检查报告
    taskDefNameAndKeyMap.put("提交检查报告@项目经理提交检查报告", new String[]{"项目经理提交检查报告","task1535356447503"});
    taskDefNameAndKeyMap.put("提交检查报告@BC经理审核", new String[]{"BC经理审核","task1535356489817"});
    taskDefNameAndKeyMap.put("提交检查报告@部门风控经理审核", new String[]{"部门风控经理审批","task1599123282069"});
    taskDefNameAndKeyMap.put("提交检查报告@办事处负责人审核", new String[]{"办事处负责人审核","task1535356493002"});
    taskDefNameAndKeyMap.put("提交检查报告@分公司负责人审核", new String[]{"分公司负责人审核","task1535356495602"});
    taskDefNameAndKeyMap.put("提交检查报告@风控部副经理审核", new String[]{"风控部副经理审核","task1535356496900"});
    taskDefNameAndKeyMap.put("提交检查报告@风控部经理审核", new String[]{"风控部副经理审核","task1535356496900"}); // todo
    taskDefNameAndKeyMap.put("提交检查报告@风控副总审核", new String[]{"风控副总审核","task1535356499156"});
    taskDefNameAndKeyMap.put("提交检查报告@总经理审核", new String[]{"总经理审核","task1535356501594"});
    taskDefNameAndKeyMap.put("提交检查报告@董事长查看", new String[]{"董事长查看","task1535356504053"});

    // 补交法律资料
    taskDefNameAndKeyMap.put("补交法律资料@项目经理补交法律资料", new String[]{"项目经理补交法律资料","task1535593383186"});
    taskDefNameAndKeyMap.put("补交法律资料@风控部审核处理", new String[]{"风控部审核处理","task1535593390830"});
    taskDefNameAndKeyMap.put("补交法律资料@档案管理员接收处理", new String[]{"档案管理员接收处理","task1535593387975"});

    // 合同文件审批
    taskDefNameAndKeyMap.put("合同文件审批@责任人提交文件", new String[]{"责任人提交文件","task1561105041760"});
    taskDefNameAndKeyMap.put("合同文件审批@法务人员审核", new String[]{"法务人员审核","task1561105043289"});
    taskDefNameAndKeyMap.put("合同文件审批@责任人接收文件", new String[]{"责任人接收文件","task1561105045176"});

    // 登记项目还款
    taskDefNameAndKeyMap.put("登记项目还款@项目经理登记还款", new String[]{"项目经理登记还款","task1562633329774"});
    taskDefNameAndKeyMap.put("登记项目还款@综合人员复核台账", new String[]{"综合人员复核台账","task1562633332994"});

    // 调查报告评审(风控经理独立审批环节 新流程中没有)
    taskDefNameAndKeyMap.put("项目评审@A经理提交评审报告", new String[]{"A经理提交评审报告","task1535432888108"});
    taskDefNameAndKeyMap.put("项目评审@项目B经理审核", new String[]{"项目B经理审核","task1535432889889"});
    taskDefNameAndKeyMap.put("项目评审@办事处负责人审批", new String[]{"办事处负责人审批","task1535432891562"});
    taskDefNameAndKeyMap.put("项目评审@部门风控经理审批", new String[]{"部门风控经理审批","task1535433080256"});
    taskDefNameAndKeyMap.put("项目评审@分公司负责人审批", new String[]{"分公司负责人审批","task1535432893607"});
    taskDefNameAndKeyMap.put("项目评审@C经理提交风险审核报告", new String[]{"C经理提交风险审核报告","task1535433057026"});
    taskDefNameAndKeyMap.put("项目评审@公司融资部审批", new String[]{"公司融资部审批","task1535433063214"});
    taskDefNameAndKeyMap.put("项目评审@林业项目部审批", new String[]{"公司融资部审批","task1535433063214"});
    taskDefNameAndKeyMap.put("项目评审@风控内勤设置D角", new String[]{"风控内勤设置D角","task1535433078572"});
    taskDefNameAndKeyMap.put("项目评审@D经理审核评审报告", new String[]{"D经理审核评审报告","task1535433095663"});
    taskDefNameAndKeyMap.put("项目评审@风控责任人审核", new String[]{"风控责任人审核","task1535433097680"}); // 会签
    taskDefNameAndKeyMap.put("项目评审@上会前总经理审核", new String[]{"上会前总经理审核","task1535433101491"});
    taskDefNameAndKeyMap.put("项目评审@评审会主任审核", new String[]{"评审会主任审核","task1535433103583"});
    taskDefNameAndKeyMap.put("项目评审@评审秘书确定评审委员", new String[]{"评审秘书确定评审委员会","task1535433311622"});
    taskDefNameAndKeyMap.put("项目评审@评审委员提交意见", new String[]{"评审委员提交意见","task1535433314226"});// 会签
    taskDefNameAndKeyMap.put("项目评审@评审秘书提交会议纪要", new String[]{"评审秘书提交会议纪要","task1535433316115"});
    taskDefNameAndKeyMap.put("项目评审@评审会主任审批签字", new String[]{"评审会主任审批签字","task1562220491234"});

    taskDefNameAndKeyMap.put("项目评审@独立评审D经理审核并投票", new String[]{"独立评审D经理审核并投票","task1535433106332"});
    taskDefNameAndKeyMap.put("项目评审@独立评审委员投票", new String[]{"独立评审委员投票","task1535433107939"});// 会签
    taskDefNameAndKeyMap.put("项目评审@独立评审总经理审批签字", new String[]{"独立评审总经理审批签字","task1562215941707"});
    taskDefNameAndKeyMap.put("项目评审@独立评审董事长审批签字", new String[]{"独立评审董事长审批签字","task1562216257691"});

    taskDefNameAndKeyMap.put("项目评审@负责人独立审批签字", new String[]{"负责人独立审批签字","task1571280651219"});
    taskDefNameAndKeyMap.put("项目评审@审保秘书汇总意见", new String[]{"审保秘书汇总意见","task1535433116401"});

    // 展期评审
    taskDefNameAndKeyMap.put("zq项目评审@A经理提交评审报告", new String[]{"A经理提交评审报告","task1535530725571"});
    taskDefNameAndKeyMap.put("zq项目评审@项目B经理审核", new String[]{"项目B经理审核","task1535530755459"});
    taskDefNameAndKeyMap.put("zq项目评审@办事处负责人审批", new String[]{"办事处负责人审批","task1535530776877"});
    taskDefNameAndKeyMap.put("zq项目评审@部门风控经理审批", new String[]{"部门风控经理审批","task1535531312595"});
    taskDefNameAndKeyMap.put("zq项目评审@分公司负责人审批", new String[]{"分公司负责人审批","task1535530803867"});
    taskDefNameAndKeyMap.put("zq项目评审@C经理提交风险审核报告", new String[]{"C经理提交风险审核报告","task1535530854063"});
    taskDefNameAndKeyMap.put("zq项目评审@公司融资部审批", new String[]{"公司融资部审批","task1535530893755"});
    taskDefNameAndKeyMap.put("zq项目评审@林业项目部审批", new String[]{"公司融资部审批","task1535530893755"});
    taskDefNameAndKeyMap.put("zq项目评审@风控内勤设置D角", new String[]{"风控内勤设置D角","task1535533444991"});
    taskDefNameAndKeyMap.put("zq项目评审@D经理审核评审报告", new String[]{"D经理审核评审报告","task1535533596374"});
    taskDefNameAndKeyMap.put("zq项目评审@风控责任人审核", new String[]{"风控责任人审核","task1535703625372"}); // 会签
    taskDefNameAndKeyMap.put("zq项目评审@上会前总经理审核", new String[]{"上会前总经理审核","task1535703670895"});
    taskDefNameAndKeyMap.put("zq项目评审@评审会主任审核", new String[]{"评审会主任审核","task1535703693232"});
    taskDefNameAndKeyMap.put("zq项目评审@评审秘书确定评审委员", new String[]{"评审秘书确定评审委员","task1535530921953"});
    taskDefNameAndKeyMap.put("zq项目评审@评审委员提交意见", new String[]{"各评审委员提交评审意见","task1535531008710"});// 会签
    taskDefNameAndKeyMap.put("zq项目评审@评审秘书提交会议纪要", new String[]{"评审秘书提交会议纪要","task1535531061729"});
    taskDefNameAndKeyMap.put("zq项目评审@评审会主任审批签字", new String[]{"评审会主任审批签字","task1535703857767"});

    taskDefNameAndKeyMap.put("zq项目评审@独立评审D经理审核并投票", new String[]{"D经理审核并投票","task1535533453565"});
    taskDefNameAndKeyMap.put("zq项目评审@独立评审委员投票", new String[]{"独立评审委员投票","task1535703726061"});// 会签
    taskDefNameAndKeyMap.put("zq项目评审@独立评审总经理审批签字", new String[]{"总经理审批签字","task1535703813100"});
    taskDefNameAndKeyMap.put("zq项目评审@独立评审董事长审批签字", new String[]{"董事长审批签字","task1535703832540"});

    taskDefNameAndKeyMap.put("zq项目评审@负责人独立审批签字", new String[]{"负责人独立审批签字","task1535533010682"});
    taskDefNameAndKeyMap.put("zq项目评审@审保秘书汇总意见", new String[]{"审保秘书汇总意见","task1535703769096"});

    // 复议
    taskDefNameAndKeyMap.put("fy项目评审@A经理提交评审报告", new String[]{"A经理提交评审报告","task1560243325522"});
    taskDefNameAndKeyMap.put("fy项目评审@项目B经理审核", new String[]{"项目B经理审核","task1560243446581"});
    taskDefNameAndKeyMap.put("fy项目评审@办事处负责人审批", new String[]{"办事处负责人审批","task1560243487479"});
    taskDefNameAndKeyMap.put("fy项目评审@部门风控经理审批", new String[]{"部门风控经理审批","task1560243493708"});
    taskDefNameAndKeyMap.put("fy项目评审@分公司负责人审批", new String[]{"分公司负责人审批","task1560243506597"});
    taskDefNameAndKeyMap.put("fy项目评审@C经理提交风险审核报告", new String[]{"C经理提交风险审核报告","task1560243826467"});
    taskDefNameAndKeyMap.put("fy项目评审@公司融资部审批", new String[]{"公司融资部审批","task1560243835689"});
    taskDefNameAndKeyMap.put("fy项目评审@林业项目部审批", new String[]{"公司融资部审批","task1560243835689"});
    taskDefNameAndKeyMap.put("fy项目评审@风控内勤设置D角", new String[]{"风控内勤设置D角","task1560243522142"});
    taskDefNameAndKeyMap.put("fy项目评审@D经理审核评审报告", new String[]{"D经理审核评审报告","task1560243535035"});
    taskDefNameAndKeyMap.put("fy项目评审@风控责任人审核", new String[]{"风控责任人审核","task1560243639901"}); // 会签
    taskDefNameAndKeyMap.put("fy项目评审@上会前总经理审核", new String[]{"上会前总经理审核","task1560243655208"});
    taskDefNameAndKeyMap.put("fy项目评审@评审会主任审核", new String[]{"评审会主任审核","task1560243672091"});
    taskDefNameAndKeyMap.put("fy项目评审@评审秘书确定评审委员", new String[]{"评审秘书确定评审委员会","task1560243915664"});
    taskDefNameAndKeyMap.put("fy项目评审@评审委员提交意见", new String[]{"各评审委员提交意见","task1560243913751"});// 会签
    taskDefNameAndKeyMap.put("fy项目评审@评审秘书提交会议纪要", new String[]{"评审秘书提交会议纪要","task1560243910374"});
    taskDefNameAndKeyMap.put("fy项目评审@评审会主任审批签字", new String[]{"评审会主任审批签字","task1560243682253"});

    taskDefNameAndKeyMap.put("fy项目评审@独立评审D经理审核并投票", new String[]{"D经理审核并投票","task1560243528981"});
    taskDefNameAndKeyMap.put("fy项目评审@独立评审委员投票", new String[]{"独立评审委员会投票","task1560243550276"});// 会签
    taskDefNameAndKeyMap.put("fy项目评审@独立评审总经理审批签字", new String[]{"总经理审批签字","task1560243593110"});
    taskDefNameAndKeyMap.put("fy项目评审@独立评审董事长审批签字", new String[]{"董事长审批签字","task1560243613045"});

    taskDefNameAndKeyMap.put("fy项目评审@负责人独立审批签字", new String[]{"分公司负责人审批","task1560243506597"});
    taskDefNameAndKeyMap.put("fy项目评审@审保秘书汇总意见", new String[]{"审保秘书汇总意见","task1560243561136"});

    // 增量
    taskDefNameAndKeyMap.put("zl项目评审@A经理提交评审报告", new String[]{"A经理提交评审报告","task1536994621916"});
    taskDefNameAndKeyMap.put("zl项目评审@项目B经理审核", new String[]{"项目B经理审核","task1536994646235"});
    taskDefNameAndKeyMap.put("zl项目评审@办事处负责人审批", new String[]{"办事处负责人审批","task1536994663564"});
    taskDefNameAndKeyMap.put("zl项目评审@部门风控经理审批", new String[]{"部门风控经理审批","task1536995133311"});
    taskDefNameAndKeyMap.put("zl项目评审@分公司负责人审批", new String[]{"分公司负责人审批","task1536994684037"});
    taskDefNameAndKeyMap.put("zl项目评审@C经理提交风险审核报告", new String[]{"C经理提交风险审核报告","task1536994700684"});
    taskDefNameAndKeyMap.put("zl项目评审@公司融资部审批", new String[]{"公司融资部审批","task1536994728972"});
    taskDefNameAndKeyMap.put("zl项目评审@林业项目部审批", new String[]{"公司融资部审批","task1536994728972"});
    taskDefNameAndKeyMap.put("zl项目评审@风控内勤设置D角", new String[]{"风控内勤设置D角","task1536994816724"});
    taskDefNameAndKeyMap.put("zl项目评审@D经理审核评审报告", new String[]{"D经理审核评审报告","task1536994837668"});
    taskDefNameAndKeyMap.put("zl项目评审@风控责任人审核", new String[]{"风控负责人审核","task1536994862157"}); // 会签
    taskDefNameAndKeyMap.put("zl项目评审@上会前总经理审核", new String[]{"上会前总经理审批","task1536994900541"});
    taskDefNameAndKeyMap.put("zl项目评审@评审会主任审核", new String[]{"评审会主任审核","task1536994924837"});
    taskDefNameAndKeyMap.put("zl项目评审@评审秘书确定评审委员", new String[]{"评审秘书确定评审委员","task1536994749740"});
    taskDefNameAndKeyMap.put("zl项目评审@评审委员提交意见", new String[]{"各评审委员提交意见","task1536994768212"});// 会签
    taskDefNameAndKeyMap.put("zl项目评审@评审秘书提交会议纪要", new String[]{"评审秘书提交会议纪要","task1536994780060"});
    taskDefNameAndKeyMap.put("zl项目评审@评审会主任审批签字", new String[]{"评审会主任审批签字","task1536994954213"});

    taskDefNameAndKeyMap.put("zl项目评审@独立评审D经理审核并投票", new String[]{"D经理审核并投票","task1536995017253"});
    taskDefNameAndKeyMap.put("zl项目评审@独立评审委员投票", new String[]{"独立评审委员投票","task1536995039373"});// 会签
    taskDefNameAndKeyMap.put("zl项目评审@独立评审总经理审批签字", new String[]{"总经理审批签字","task1536995097686"});
    taskDefNameAndKeyMap.put("zl项目评审@独立评审董事长审批签字", new String[]{"董事长审批签字","task1536995112166"});

    taskDefNameAndKeyMap.put("zl项目评审@负责人独立审批签字", new String[]{"负责人独立审批签字","task1536995176942"});
    taskDefNameAndKeyMap.put("zl项目评审@审保秘书汇总意见", new String[]{"审保秘书汇总意见","task1536995065182"});


    // 核保放款流程
    taskDefNameAndKeyMap.put("核保放款@项目经理提交核保资料", new String[]{"项目经理提交核保资料","task1558072967584"});

    // 项目终结流程
    taskDefNameAndKeyMap.put("项目终结流程@项目经理提交申请", new String[]{"项目经理提交申请","task1536113358528"});
    taskDefNameAndKeyMap.put("项目终结流程@BC经理审核", new String[]{"BC经理审核","task1536113359730"});
    taskDefNameAndKeyMap.put("项目终结流程@风控副经理审核", new String[]{"风控副经理审核","task1536113360866"});
    taskDefNameAndKeyMap.put("项目终结流程@风控经理审核", new String[]{"风控副经理审核","task1536113360866"});
    taskDefNameAndKeyMap.put("项目终结流程@财务部经理审核", new String[]{"财务部经理审核","task1536113362418"});
    taskDefNameAndKeyMap.put("项目终结流程@总经理审核", new String[]{"总经理审核","task1536113364257"});
    taskDefNameAndKeyMap.put("项目终结流程@董事长审核", new String[]{"董事长审核","task1536113365906"});
    taskDefNameAndKeyMap.put("项目终结流程@档案室退权证和财务处退保证金", new String[]{"财务处退保证金","task1536113367458"});

    // 代偿项目移交法务流程
    taskDefNameAndKeyMap.put("代偿项目移交@项目经理申请移交", new String[]{"项目经理申请移交","task1535511537223"});
    taskDefNameAndKeyMap.put("代偿项目移交@BC经理审核", new String[]{"BC经理审核","task1535511899716"});
    taskDefNameAndKeyMap.put("代偿项目移交@办事处负责人审批", new String[]{"办事处负责人审批","task1535511961372"});
    taskDefNameAndKeyMap.put("代偿项目移交@分公司负责人审核", new String[]{"分公司负责人审核","task1535512080829"});
    taskDefNameAndKeyMap.put("代偿项目移交@业务副总审核", new String[]{"业务副总审核","task1562916465110"});
    taskDefNameAndKeyMap.put("代偿项目移交@法务副总审批", new String[]{"业务副总审核","task1562916465110"});
    taskDefNameAndKeyMap.put("代偿项目移交@总经理审核", new String[]{"总经理审核","task1562916474390"});
    taskDefNameAndKeyMap.put("代偿项目移交@总经理审批", new String[]{"总经理审核","task1562916474390"});
    taskDefNameAndKeyMap.put("代偿项目移交@保全部经理接收处理", new String[]{"法务部经理接收处理","task1535512170717"});
    taskDefNameAndKeyMap.put("代偿项目移交@法务部经理接收处理", new String[]{"法务部经理接收处理","task1535512170717"});
    taskDefNameAndKeyMap.put("代偿项目移交@追偿监管人接收", new String[]{"法务部经理接收处理","task1535512170717"});
    taskDefNameAndKeyMap.put("代偿项目移交@分公司负责人处理", new String[]{"法务部经理接收处理","task1535512170717"});
    taskDefNameAndKeyMap.put("代偿项目移交@追偿主责任人接收", new String[]{"追偿主责任人接收","task1535512348555"});
    taskDefNameAndKeyMap.put("代偿项目移交@项目经理补充材料", new String[]{"项目经理补充材料","task1562916749743"});

    // 申请利息补贴
    taskDefNameAndKeyMap.put("申请利息补贴@项目经理提交申请", new String[] {"项目经理提交申请","task1543472491623"});
    taskDefNameAndKeyMap.put("申请利息补贴@分公司财务审核", new String[] {"分公司财务审核","task1543472493818"});
    taskDefNameAndKeyMap.put("申请利息补贴@分公司负责人审核", new String[] {"分公司负责人审核","task1543472495998"});
    taskDefNameAndKeyMap.put("申请利息补贴@财务经办人审核", new String[] {"财务经办人审核","task1543472500255"});
    taskDefNameAndKeyMap.put("申请利息补贴@财务部门经理审核", new String[] {"财务部门经理审核","task1543472503945"});

    // 客户退费审批流程
    taskDefNameAndKeyMap.put("客户退费流程@项目经理提交申请",new String[]{"项目经理提交申请","task1535443431960"});
    taskDefNameAndKeyMap.put("客户退费流程@部门负责人审核",new String[]{"部门负责人审核","task1535443464639"});
    taskDefNameAndKeyMap.put("客户退费流程@风控副经理审核",new String[]{"风控副经理审核","task1535443482380"});
    // 老流程有该环节 - 新流程没有
    taskDefNameAndKeyMap.put("客户退费流程@风控部经理审核",new String[]{"风控副经理审核","task1535443482380"});
    taskDefNameAndKeyMap.put("客户退费流程@风控副总审核",new String[]{"风控副总审核","task1577960609898"});
    taskDefNameAndKeyMap.put("客户退费流程@财务部经理审核",new String[]{"财务部经理审核","task1555382895812"});
    taskDefNameAndKeyMap.put("客户退费流程@业务副总审批",new String[]{"业务副总审批","task1535443508494"});
    taskDefNameAndKeyMap.put("客户退费流程@财务副总审核",new String[]{"财务副总审核","task1563503766558"});
    taskDefNameAndKeyMap.put("客户退费流程@财务副总审批",new String[]{"财务副总审核","task1563503766558"});
    taskDefNameAndKeyMap.put("客户退费流程@总经理审批",new String[]{"总经理审批","task1535443540388"});
    taskDefNameAndKeyMap.put("客户退费流程@董事长审批",new String[]{"董事长审批","task1535443559672"});
    taskDefNameAndKeyMap.put("客户退费流程@财务出纳退费",new String[]{"财务出纳退费","task1535443576474"});

    // 被动代偿申请
    taskDefNameAndKeyMap.put("被动代偿申请@项目主责任人提交申请", new String[] {"项目主责任人提交申请","task1535443297739"});
    taskDefNameAndKeyMap.put("被动代偿申请@部门负责人和风控经理审批", new String[] {"部门负责人审批","task1535443355164"}); // 会签节点
    // 老系统少了分公司负责人和风控部经理审批
    taskDefNameAndKeyMap.put("被动代偿申请@风控副总审核", new String[] {"风控副总审核","task1535443469809"});
    taskDefNameAndKeyMap.put("被动代偿申请@财务部经理审核", new String[] {"财务部经理审核","task1563158143085"});
    taskDefNameAndKeyMap.put("被动代偿申请@业务副总审核", new String[] {"业务副总审核","task1563158144756"});
    taskDefNameAndKeyMap.put("被动代偿申请@财务副总审核", new String[] {"财务副总审核","task1563158146483"});
    taskDefNameAndKeyMap.put("被动代偿申请@总经理审批", new String[] {"总经理审批","task1535443749106"});
    taskDefNameAndKeyMap.put("被动代偿申请@董事长审批", new String[] {"董事长审批","task1535443717445"});
    taskDefNameAndKeyMap.put("被动代偿申请@财务部执行代偿", new String[] {"财务部执行代偿","task1535443680769"});

    taskDefNameAndKeyMap.put("代偿申请流程@项目主责任人提交申请", new String[] {"项目主责任人提交申请","task1535443297739"});
    taskDefNameAndKeyMap.put("代偿申请流程@部门负责人和风控经理审批", new String[] {"部门负责人审批","task1535443355164"}); // 会签节点
    // 老系统少了分公司负责人和风控部经理审批
    taskDefNameAndKeyMap.put("代偿申请流程@风控副总审核", new String[] {"风控副总审核","task1535443469809"});
    taskDefNameAndKeyMap.put("代偿申请流程@风控副总审批", new String[] {"风控副总审核","task1535443469809"});
    taskDefNameAndKeyMap.put("代偿申请流程@财务部经理审核", new String[] {"财务部经理审核","task1563158143085"});
    taskDefNameAndKeyMap.put("代偿申请流程@业务副总审核", new String[] {"业务副总审核","task1563158144756"});
    taskDefNameAndKeyMap.put("代偿申请流程@财务副总审核", new String[] {"财务副总审核","task1563158146483"});
    taskDefNameAndKeyMap.put("代偿申请流程@总经理审批", new String[] {"总经理审批","task1535443749106"});
    taskDefNameAndKeyMap.put("代偿申请流程@董事长审批", new String[] {"董事长审批","task1535443717445"});
    taskDefNameAndKeyMap.put("代偿申请流程@财务部执行代偿", new String[] {"财务部执行代偿","task1535443680769"});

    //  次年收费审核
    taskDefNameAndKeyMap.put("次年收费审核@项目经理提交资料", new String[]{"项目经理提交资料","task1535506300139"});
    taskDefNameAndKeyMap.put("次年收费审核@部门负责人审核", new String[]{"部门负责人审核","task1535506358519"});
    taskDefNameAndKeyMap.put("次年收费审核@风控部经理审核", new String[]{"风控部经理审核","task1535506387199"});
    taskDefNameAndKeyMap.put("次年收费审核@财务部经理审核", new String[]{"财务部经理审核","task1535506439540"});
    // 老流程有该环节 - 新流程没有
    taskDefNameAndKeyMap.put("次年收费审核@业务副总审核", new String[]{"财务部经理审核","task1535506439540"});
    // 老流程有该环节 - 新流程没有
    taskDefNameAndKeyMap.put("次年收费审核@总经理审核", new String[]{"财务部经理审核","task1535506439540"});
    taskDefNameAndKeyMap.put("次年收费审核@财务部收费处理", new String[]{"财务部收费处理","task1535506419510"});

    // 服务性(主动)代偿受理(item-accept-guoqiao-hny)
    taskDefNameAndKeyMap.put("服务性代偿受理@项目经理提交申请", new String[]{"项目经理提交申请","task1535444077248"});
    taskDefNameAndKeyMap.put("服务性代偿受理@办事处负责人审核", new String[]{"办事处负责人审核","task1535444097093"});
    taskDefNameAndKeyMap.put("服务性代偿受理@分公司负责人审核", new String[]{"分公司负责人审核","task1535444131823"});
    taskDefNameAndKeyMap.put("服务性代偿受理@公司融资部审批", new String[]{"公司融资部审批","task1569398954208"});
    taskDefNameAndKeyMap.put("服务性代偿受理@业务副总经理审批", new String[]{"业务副总经理审批","task1535444263828"});
    taskDefNameAndKeyMap.put("主动代偿受理@项目经理提交申请", new String[]{"项目经理提交申请","task1535444077248"});
    taskDefNameAndKeyMap.put("主动代偿受理@办事处负责人审核", new String[]{"办事处负责人审核","task1535444097093"});
    taskDefNameAndKeyMap.put("主动代偿受理@分公司负责人审核", new String[]{"分公司负责人审核","task1535444131823"});
    taskDefNameAndKeyMap.put("主动代偿受理@公司融资部审批", new String[]{"公司融资部审批","task1569398954208"});
    taskDefNameAndKeyMap.put("主动代偿受理@业务副总经理审批", new String[]{"业务副总经理审批","task1535444263828"});

    // 项目增量受理(item-accept-increase-hny)
    taskDefNameAndKeyMap.put("增量受理@项目经理提交申请", new String[] {"受理人提交资料","task1535611990610"});
    taskDefNameAndKeyMap.put("增量受理@办事处负责人审批", new String[] {"办事处负责人审批","task1535612063868"});
    taskDefNameAndKeyMap.put("增量受理@分公司负责人审批", new String[] {"分公司负责人审批","task1535612205276"});
    taskDefNameAndKeyMap.put("增量受理@公司融资部审批", new String[] {"公司融资部审批","task1535612255450"});
    taskDefNameAndKeyMap.put("增量受理@林业项目部审批", new String[] {"公司融资部审批","task1535612255450"});
    taskDefNameAndKeyMap.put("增量受理@业务副总经理审批", new String[] {"业务副总经理审批","task1535612282296"});
    taskDefNameAndKeyMap.put("增量受理@A经理出调查协议", new String[] {"A经理出调查协议","task1535612315287"});
    taskDefNameAndKeyMap.put("增量受理@审计内勤指派事务所", new String[] {"审计内勤指派事务所","task1535612338009"});

    // 委托代偿审批
    taskDefNameAndKeyMap.put("委托代偿审批@项目经理提交申请", new String[]{"项目经理提交申请","task1601198809958"});
    taskDefNameAndKeyMap.put("委托代偿审批@BC经理审核", new String[]{"BC经理审批","task1601198815913"});
    taskDefNameAndKeyMap.put("委托代偿审批@办事处负责人审批", new String[]{"办事处负责人审批","task1601198912207"});
    taskDefNameAndKeyMap.put("委托代偿审批@分公司负责人审批", new String[]{"分公司负责人审批","task1601198818017"});
    taskDefNameAndKeyMap.put("委托代偿审批@分管副总审批", new String[]{"分管副总审批","task1601198936919"});
    taskDefNameAndKeyMap.put("委托代偿审批@委托代偿经办人审批", new String[]{"委托代偿经办人审批","task1601198944762"});
    taskDefNameAndKeyMap.put("委托代偿审批@经办人审核材料", new String[]{"委托代偿经办人审批","task1601198944762"});
    taskDefNameAndKeyMap.put("委托代偿审批@法务部经理审批", new String[]{"法务部经理审批","task1601198955220"});
    taskDefNameAndKeyMap.put("委托代偿审批@总经理审批", new String[]{"总经理审批","task1601198958934"});
    taskDefNameAndKeyMap.put("委托代偿审批@董事长审批", new String[]{"董事长审批","task1601198961543"});
    taskDefNameAndKeyMap.put("委托代偿审批@经办人处理放款", new String[]{"经办人处理放款","task1601198963631"});

    // 更替换反担保
    taskDefNameAndKeyMap.put("置换反担保@A经理提交申请", new String[] {"A经理提交申请","task1535438825154"});
    taskDefNameAndKeyMap.put("置换反担保@B经理提交审核", new String[] {"B经理提交审核","task1535439045582"});
    taskDefNameAndKeyMap.put("置换反担保@办事处负责人审批", new String[] {"办事处负责人审批","task1535439159158"});
    taskDefNameAndKeyMap.put("zhfdb项目评审@部门风控经理审批", new String[] {"部门风控经理审批","task1535767462937"});
    taskDefNameAndKeyMap.put("置换反担保@分公司负责人审批", new String[] {"分公司负责人审批","task1535439376531"});
    taskDefNameAndKeyMap.put("置换反担保@风控内勤设置D角", new String[] {"风控内勤设置D角","task1535443211707"});
    taskDefNameAndKeyMap.put("置换反担保@独立评审委员投票", new String[] {"独立评审委员投票","task1535447612800"});
    taskDefNameAndKeyMap.put("置换反担保@审保秘书汇总意见", new String[] {"审保秘书汇总意见","task1535447783517"});
    taskDefNameAndKeyMap.put("置换反担保@独立评审总经理审批签字", new String[] {"独立评审总经理审批签字","task1535447855071"});
    taskDefNameAndKeyMap.put("置换反担保@独立评审董事长审批签字", new String[] {"独立评审董事长审批签字","task1535447884153"});
    taskDefNameAndKeyMap.put("置换反担保@C经理提交风险审核报告", new String[] {"C经理提交风险审核报告","task1535439447680"});
    taskDefNameAndKeyMap.put("置换反担保@公司融资部审批", new String[] {"公司融资部审批","task1535439523327"});
    taskDefNameAndKeyMap.put("置换反担保@林业项目部审批", new String[] {"公司融资部审批","task1535439523327"});
    taskDefNameAndKeyMap.put("置换反担保@D经理审核资料", new String[] {"D经理审核资料","task1535443307003"});
    taskDefNameAndKeyMap.put("置换反担保@风控责任人审核", new String[] {"风控责任人审核","task1535443450164"});
    taskDefNameAndKeyMap.put("置换反担保@上会前总经理审核", new String[] {"上会前总经理审核","task1535445802227"});
    taskDefNameAndKeyMap.put("置换反担保@评审会主任审核", new String[] {"评审会主任审核","task1535445846140"});
    taskDefNameAndKeyMap.put("置换反担保@评审秘书确定评审委员", new String[] {"评审秘书确定评审委员","task1535449652421"});
    taskDefNameAndKeyMap.put("置换反担保@评审委员提交意见", new String[] {"评审委员提交意见","task1535449654533"});
    taskDefNameAndKeyMap.put("置换反担保@评审秘书提交会议纪要", new String[] {"评审秘书提交会议纪要","task1535449658028"});
    taskDefNameAndKeyMap.put("置换反担保@评审会主任审批签字", new String[] {"评审会主任审批签字","task1535449233043"});
    taskDefNameAndKeyMap.put("zhfdb项目评审@负责人独立审批签字", new String[] {"负责人独立审批签字","task1575011571871"});

    // 工作移交审批
//    taskDefNameAndKeyMap.put("项目移交@原项目经理提交申请", new String[] {"原项目经理提交申请","task1535530600312"});
//    taskDefNameAndKeyMap.put("项目移交@部门经理审核", new String[] {"办事处负责人审批","task1535530818130"});
//    taskDefNameAndKeyMap.put("项目移交@分公司负责人审批", new String[] {"分公司负责人审批","task1535530862659"});
//    taskDefNameAndKeyMap.put("项目移交@新分公司负责人接收", new String[] {"新分公司负责人接收","task1535530901483"});
//    taskDefNameAndKeyMap.put("项目移交@新办事处负责人接收", new String[] {"新办事处负责人接收","task1535531217465"});
//    taskDefNameAndKeyMap.put("项目移交@新项目经理确认接受", new String[] {"新项目经理确认接受","task1535531800056"});

  }

  public static void findProdDefAndTaskDefMigrationIdMap(DbUtil targetDbUtil) throws SQLException {
    List<Map> list = new ArrayList<Map>();
    int index = 1;
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      String sql = "SELECT SOURCE_ID,TARGET_ID,TARGET_KEY FROM MIGRATION_ID_MAP WHERE CATEGORY = ? OR CATEGORY = ?";
      conn = targetDbUtil.getConn();
      pstmt = conn.prepareStatement(sql);
      pstmt.setObject(1,"process_definition");
      pstmt.setObject(2,"task_definition");
      rs = pstmt.executeQuery();
      while (rs.next()) {
        Map<String,String> map = new HashMap<>();
        map.put("TARGET_ID",rs.getString("TARGET_ID"));
        map.put("TARGET_KEY",rs.getString("TARGET_KEY"));
        procDefAndTaskDefMigrationIdMap.put(rs.getString("SOURCE_ID"),map);
      }
      pstmt.close();
      rs.close();
      conn.close();
    } catch (Exception e) {
      throw e;
    } finally {
      if(pstmt !=null) {
        pstmt.close();
      }
      if(rs !=null) {
        pstmt.close();
      }
      if(conn !=null) {
        conn.close();
      }
    }
  }

  public static boolean checkMigrated(String sourceId) throws SQLException {
    List<Map> result =targetDbUtil.selectByParams("SELECT COUNT(*) COUNT_ FROM MIGRATION_ID_MAP WHERE SOURCE_ID = ? ", Arrays.asList(new String[]{sourceId}));
    if(Integer.valueOf(result.get(0).get("COUNT_").toString()) == 0){
      return false;
    }
    return true;
  }

  public static String getProcDefId(Map procInstRow) {
    String processCode = procInstRow.get("WFNAME").toString();
    String processDefinition_ = procInstRow.get("PROCESSDEFINITION_").toString();
    boolean isRunning = !procInstRow.get("OPEN_TASK_COUNT").toString().equals("0");
    String newProcDefId = DictTool.getTargetDictCode(NewProcessDefId.class, BusinessTool.getWorkflowRealWfName(procInstRow));
    if(!newProcDefId.equals(processCode)) {
      if(!(!isRunning && processCode.equals("item-sencor-loan-hny"))){
        return newProcDefId;
      }
    }
    return procDefAndTaskDefMigrationIdMap.get(processDefinition_).get("TARGET_ID");
  }

  public static String[] getTaskDefNameAndKey(Map procInstRow, String procDefName,String taskDefName) {
    String processCode = BusinessTool.getWorkflowRealWfName(procInstRow);
    boolean isRunning = !procInstRow.get("OPEN_TASK_COUNT").toString().equals("0");
    String newProcDefId = DictTool.getTargetDictCode(NewProcessDefId.class, processCode);
    if(!newProcDefId.equals(processCode)) {
      if(!(!isRunning && processCode.equals("item-sencor-loan-hny"))) {
        if(processCode.endsWith("-zq")){
          taskDefName = "zq"+taskDefName ;
        }else if(processCode.endsWith("-zl")){
          taskDefName = "zl"+taskDefName ;
        }else if(processCode.endsWith("-fy")){
          taskDefName = "fy"+taskDefName ;
        } else if(processCode.contains("replace-pledge")){
          if(taskDefName.contains("项目评审")) {
            taskDefName = "zhfdb"+taskDefName;
          }
        }

        return taskDefNameAndKeyMap.get(taskDefName);
      }
    }
    return new String[]{taskDefName,procDefAndTaskDefMigrationIdMap.get(procDefName + "@" + taskDefName).get("TARGET_KEY")};
  }

  /**
   * 根据字典DATA_CODE获取字典名称
   * @param dictCode
   * @param dataCode
   * @return
   */
  public static String getOldDictDataNameByDictCodeAndDataCode(String dictCode,String dataCode) {
    if(dictCode == null || dataCode == null) {
      return "";
    }
    Optional<Map> dictDataMap = oldDictList.stream()
        .filter(dictData->dictData.get("DICT_CODE").toString().equals(dictCode) && dictData.get("DATA_CODE").toString().equals(dataCode))
        .findFirst();
    if(dictDataMap.isPresent()){
      return dictDataMap.get().get("DATA_NAME") == null ? "" : dictDataMap.get().get("DATA_NAME").toString();
    }
    return "";
  }

  public static String getOldDictDataNameByDictCodeAndDataCode(String dictCode,Object dataCode) {
    if(dataCode == null || dataCode.toString().equals("")) {
      return "";
    }
    return getOldDictDataNameByDictCodeAndDataCode(dictCode, dataCode.toString());
  }

    // 胡三(husan) =》 husan
  public static String getEmpCode(String empQualifiedName) {
    if(empQualifiedName == null || empQualifiedName.equals("")) {
      return null;
    }
    if(empQualifiedName.contains("(")){
      return empQualifiedName.split("\\(")[1].split("\\)")[0];
    }else{
      return empQualifiedName;
    }

  }

  // 胡三(husan) => 胡三
  public static String getEmpName(String empQualifiedName) {
    return empQualifiedName.split("\\(")[0];
  }

  /**
   * 分割用户中文名和用户编码
   * 胡三(husan)|刘四(liusi) => ["胡三,刘四","husan,liusi"]
   * @param empCodeAndNames
   * @return
   */
  public static String[] getEmpCodeAndNameSeperated(String empCodeAndNames, String splitStr, String joinStr, Object createTs){
    String joinedEmpCodeAndNames = getJoinedUserIdAndNames(empCodeAndNames,createTs, splitStr,joinStr);
    if(joinedEmpCodeAndNames == null) {
      return null;
    }
    return new String[]{
        joinedEmpCodeAndNames.substring(0, joinedEmpCodeAndNames.indexOf("("))
        ,joinedEmpCodeAndNames.substring(joinedEmpCodeAndNames.indexOf("(")+1, joinedEmpCodeAndNames.indexOf(")"))
    };
  }

  public static String getNextStepUser(Object nextStepUser, Object createTs) {
    return getJoinedUserIdAndNames(nextStepUser, createTs,";",",");
  }

  public static String getJoinedUserIdAndNames(Object nextStepUser, Object createTs, String splitStr,String joinStr) {
    if(nextStepUser == null) {
      return null;
    }
    if(nextStepUser.toString().equals("")) {
      return null;
    }
    String[] nextStepUserArr = new String[]{};
    if(splitStr.equals("|")) {
      nextStepUserArr = nextStepUser.toString().split("\\|");
    }else {
      nextStepUserArr = nextStepUser.toString().split(splitStr);
    }

    String nextStepUserCodes = "";
    String nextStepUserNames = "";
    for(int i = 0;i<nextStepUserArr.length;i++) {
      String nextStepUserLoop = nextStepUserArr[i];
      String realNextStepUserCode = getTaskRealActorId("HNY."+getEmpCode(nextStepUserLoop), createTs);
      if(i == nextStepUserArr.length - 1) {
        nextStepUserCodes = nextStepUserCodes + realNextStepUserCode;
        nextStepUserNames = nextStepUserNames + getEmpNameByEmpCode(realNextStepUserCode);
      } else {
        nextStepUserCodes = nextStepUserCodes + realNextStepUserCode + joinStr;
        nextStepUserNames = nextStepUserNames + getEmpNameByEmpCode(realNextStepUserCode) + joinStr;
      }
    }

    return nextStepUserNames + "("+nextStepUserCodes+")";
  }

  private static String convertApplyTimeToMonth(String applyTime) {
    if(applyTime == null || applyTime.trim().equals("")) {
      return applyTime;
    }
    try {
      if (applyTime.contains("年")) {
        return Integer.parseInt(applyTime.trim().replace("年", "")) * 12 + "";
      } else if (applyTime.contains("月")) {
        return applyTime.trim().replace("月", "");
      }
    }catch(Exception e) {
      return applyTime;
    }
    return applyTime;
  }

  public static String convertApplyTimeToMonth(Object applyTime) {
    if(applyTime == null ){
      return null;
    }

    return convertApplyTimeToMonth(applyTime.toString());
  }

  public static Long calcMonthBetweenTwoDate(Object dateOne,Object dateTwo){
    Date dateOneD = Tool.toDate(dateOne);
    Date dateTwoD = Tool.toDate(dateTwo);
    if(dateOneD == null || dateTwoD == null) {
      return null;
    }
    long diffInMillies = Math.abs(dateTwoD.getTime() - dateOneD.getTime());
    if(diffInMillies <= 0) {
      return null;
    }
    long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);

    long month = diff / 30;

    if(month == 0) {
      return 1l;
    }

    return month;
  }

  public static BigDecimal conMoeny(Object appMoeny) {
    try{
      return covertToBigDecimal(appMoeny);
    }catch (Exception e){
      return  null;
    }
  }

  public static String getEmpNameByEmpCode(Object empCode) {
    if(empCode == null){
      return null;
    }
    if(empCode.equals("")){
      return null;
    }
    Optional<Map> empMapOptional = oldEmployeeList.stream().filter(oldEmployee->{
      return oldEmployee.get("EMPCODE").toString().equals(empCode);
    }).findFirst();

    if(empMapOptional.isPresent()) {
      return empMapOptional.get().get("EMPNAME").toString();
    }
    return empCode.toString();
  }

  public static String getEmpCodeByEmpName(String empName) {
    Optional<Map> empMapOptional = oldEmployeeList.stream().filter(oldEmployee->{
      return oldEmployee.get("EMPNAME").toString().equals(empName);
    }).findFirst();

    if(empMapOptional.isPresent()) {
      return empMapOptional.get().get("EMPCODE").toString();
    }
    return empName;
  }

  public static Boolean getRigOrWro(Object empName){
    if(empName == null){
      return false;
    }
    if(empName.equals("")){
      return false;
    }
      if(empName.toString().equals("101")){
        return true;
      }else{
        return false;
      }

  }

  private static Timestamp lyHandoverTs = Timestamp.valueOf("2018-10-01 00:00:00");
  private static Timestamp hwyHandoverTs = Timestamp.valueOf("2018-09-01 00:00:00");
  private static Timestamp ylpHandoverTs = Timestamp.valueOf("2019-01-01 00:00:00");

  public static String getTaskRealActorId(String originalActorId, Object createTsObj) {
    if(originalActorId == null) {
      return null;
    }
    String originalActorIdWoOrgCode = originalActorId.split("\\.")[1];
    if(createTsObj == null) {
      return originalActorIdWoOrgCode;
    }
    Timestamp createTs = (Timestamp)createTsObj;

    if(originalActorIdWoOrgCode.equals("liuya")){
//      2018.10.1
      if(createTs.compareTo(lyHandoverTs) == 1){
        return "hexuefeng";
      }
    } else if(originalActorIdWoOrgCode.equals("huwenyuan")) {
//      2018.9.1
      if(createTs.compareTo(hwyHandoverTs) == 1){
        return "zhongzhongliang";
      }
    } else if(originalActorIdWoOrgCode.equals("yinliping")) {
//      2019.1.1
      if(createTs.compareTo(ylpHandoverTs) == 1){
        return "tangshuhong";
      }
    }

    return originalActorIdWoOrgCode;

  }

  public static String getTaskRealActorId(Object originalActorId, Object createTsObj) {
    if(originalActorId == null || originalActorId.toString().equals("")) {
      return null;
    }
    return getTaskRealActorId(originalActorId.toString(), createTsObj);
  }

  public static Object getGuaranteeContractAmount(String promContractNo, SourceBusinessData sourceBusinessData) throws SQLException {
    if(promContractNo == null || promContractNo.toString().equals("")) {
      return null;
    }

    Optional<Map> maxBtItemAccountDetailOptional  = sourceBusinessData.getBtItemAccountDetailList().stream()
        .filter(btItemAccountDetail->{
          Object promContractNoLoop = btItemAccountDetail.get("PROMCONTRACTNO");
          if(promContractNoLoop == null){
            return false;
          }
          return promContractNoLoop.toString().equals(promContractNo.toString());
        })
        .max(Comparator.comparing(a->Tool.sqlTimestampToSqlDate(a.get("CREATE_TIME"))));

    if(maxBtItemAccountDetailOptional.isPresent()) {
      Map map = maxBtItemAccountDetailOptional.get();
      if(map.get("PROMSUM") == null || map.get("PROMSUM").toString().equals("")) {
        return (BigDecimal)map.get("OCCURSUM");
      } else {
        return (BigDecimal)map.get("PROMSUM");
      }
    }
    return null;
  }

  public static String getWorkflowRealWfName(Map procInstRow){
    String wfName = procInstRow.get("WFNAME").toString();
    if(wfName.contains("item-audit-hny")) {
      String wfDisplayName = procInstRow.get("WFDISPLAYNAME").toString();

      if(wfDisplayName.contains("展期")) {
        return wfName + "-zq";
      }
      if(wfDisplayName.contains("复议")) {
        return wfName + "-fy";
      }
      if(wfDisplayName.contains("增量")) {
        return wfName + "-zl";
      }
    }
    return wfName;
  }

  /**
   * 获取还款方式
   * @return
   */
  public static String getRepayType(List<Map> jwframeAuditConclusionList) throws ScriptException {
    if(jwframeAuditConclusionList.size() == 0) {
      return null;
    }
    List<String> oneTimeTypeKeywords = Arrays.asList("一次性","到期一次");
    List<String> amortizationTypeKeywords =Arrays.asList("分期");
    List<String> loopTypeKeywords = Arrays.asList("循环","滚动","第一年");

    for(Map jwframeAuditConclusion : jwframeAuditConclusionList) {
      Object strEstimate = Tool.decodeUnicode(jwframeAuditConclusionList.get(0).get("STRESTIMATE"));
      if(strEstimate == null) {
        continue;
      }
      String strEstimateStr = strEstimate.toString();
      for(String oneTimeTypeKeyword : oneTimeTypeKeywords) {
        if(strEstimateStr.contains(oneTimeTypeKeyword)) {
          return "1";
        }
      }
      for(String amortizationTypeKeyword : amortizationTypeKeywords) {
        if(strEstimateStr.contains(amortizationTypeKeyword)) {
          return "3";
        }
      }
      for(String loopTypeKeyword : loopTypeKeywords) {
        if(strEstimateStr.contains(loopTypeKeyword)) {
          return "2";
        }
      }
    }
    return null;
  }
}
